﻿package com.woniu.goods.util;

import java.util.List;

/**
 * 分页工具类
 * @author wugua
 */
public class PageUtil {
	private int pageNow ;  //当前页
	private int pageSize ; //分页单位
	private int rowCount ;  //总数据量
	private int pageCount ;  //总页数
	
	private int prevPage ;  //上一页
	private int nextPage;  //下一页
	
	private int startIndex ; //从第几条开始查询
	
	private List<?> lists ;  //数据集合
	
	public PageUtil(int pageNow, int rowCount, List<?> lists) {
		super();
		this.pageNow = pageNow;
		this.rowCount = rowCount;
		this.lists = lists;
		
		//计算 pageCount
		if(rowCount % this.getPageSize() == 0){
			this.pageCount = rowCount / this.getPageSize() ;
		}else {
			this.pageCount = rowCount / this.getPageSize() + 1;
		}
	}

	public PageUtil() {
		super();
		// TODO Auto-generated constructor stub
	}

	public int getPageNow() {
		if(this.pageNow == 0){
			this.pageNow = 1;
		}
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getPageSize() {
		this.pageSize = 2;
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPrevPage() {
		
		if(this.getPageNow() == 1){
			this.prevPage = 1;
		}else {
			this.prevPage = this.getPageNow() - 1;
		}
		
		return prevPage;
	}

	public void setPrevPage(int prevPage) {
		this.prevPage = prevPage;
	}

	public int getNextPage() {
		if(this.getPageNow() == this.getPageCount()){
			this.nextPage = this.getPageCount();
		}else {
			this.nextPage = this.getPageNow() + 1;
		}
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getStartIndex() {
		
		this.startIndex = (this.getPageNow()-1)*this.getPageSize();
		
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public List<?> getLists() {
		return lists;
	}

	public void setLists(List<?> lists) {
		this.lists = lists;
	}

}
